<template>
	<view class="store-page" style="background: #fff;">
		<!-- <nav-bar title="我的发布" :showLeftIcon="true" :leftSlot="false"></nav-bar> -->
		<view class="tab-list">
			<view v-for="(item, index) in tabsList" :key="index"
				:class="['tab-item', tabActive == item.value ? 'active-item':'']" 
				@tap="checkType(item)">
				<text>{{item.name}}</text>
			</view>
		</view>
		<scroll-view class="content-box" scroll-y>
			<template v-if="tabActive == 1">
				<view style="text-align: center;padding: 40rpx 0;" v-if="carDemands.length <= 0">
					暂无数据
				</view>
				<view :class="['vehicleSearch', item.status == '下架' ? 'opcityDom' : '']" v-for="item in carDemands" :key="item.id" @click="toDetail(item)">
					<view class="base-info">
						<view class="base-info-left row-column-center">
							<image class="header-img" src="@/static/images/headerDefault.png" mode="widthFix"></image>
							<!-- <u-icon name="account-fill" size="30rpx" color="#999"></u-icon> -->
							<text>{{item.nickName || 'XX用户'}}</text>
						</view>
						<view class="release-item">
							{{item.createTime}}发布
						</view>
					</view>
					<view class="to-place row-between">
						<view class="">
							<text>{{fomatterAdressName(item.startProvince)}} {{fomatterAdressName(item.startCity)}}</text>
							<image style="height: 8rpx;width: 35rpx;" src="@/static/images/mine/to.png" mode="widthFix">
							</image>
							<text>{{fomatterAdressName(item.endProvince)}} {{fomatterAdressName(item.endCity)}}</text>
						</view>
						<view class="place-number">
							<text v-if="item.newestQuote">
								{{item.newestQuote}}
								<text style="font-size: 24rpx;">元</text>
							</text> 
							<text v-else>暂无报价</text>
						</view>
					</view>
					<view class="car-info">
						<text>{{forrmatterEnmu(Enmu.vehicleType, item.vehicleType)}}</text>
						<text style="margin: 0 10rpx;">/</text>
						<text>{{item.quantity}}台</text>
						<text style="margin: 0 10rpx;">/</text>
						<text>{{forrmatterEnmu(Enmu.carStatusList, item.vehicleStatus)}}</text>
					</view>
					<view class="check-time">
						<text>托运日期：{{item.shippingDate}}</text>
						<text class="dimension" v-if="item.shippingDate && isTomorrow(item.shippingDate)">(明天)</text>
					</view>
					<view class="quotation">
						<view class="quotation-left">
							<view class="quotation-price">
								<!-- <text style="font-size: 44rpx;">0</text>
								<text>元起</text> -->
								<text style="font-size: 44rpx;"></text>
								<text></text>
							</view>
							<view class="quotation-Bidding">
								当前 {{item.quoteCount || 0 }} 次出价 {{item.callCount || 0}} 人联系
							</view>
						</view>
						<button class="quotation-right" @click.stop="offterVehicle(2, item)" :disabled="item.status == '下架'">
							<text>下架</text>
						</button>
					</view>
				</view>
			</template>
			<template v-else>
				<view style="text-align: center;padding: 40rpx 0;" v-if="goodDemands.length <= 0">
					暂无数据
				</view>
				<view :class="['vehicleSearch', item.status == '下架' ? 'opcityDom' : '']" v-for="item in goodDemands" :key="item.id" @click="toGoodsDetail(item)">
					<view class="to-place row-between">
						<view>
							<text>{{fomatterAdressName(item.startCity)}}</text>
							<image style="height: 8rpx;width: 35rpx;" src="@/static/images/mine/to.png" mode="widthFix">
							</image>
							<text>{{fomatterAdressName(item.endCity)}}</text>
						</view>
						<text class="place-number">{{item.expectedMinPrice}}-{{item.expectedMaxPrice}}
							<text>元</text>
						</text>
					</view>
					<view class="car-info">
						<text v-if="item.hasTransitCities == 0">途径点：无</text>
						<text v-else>途径点：{{item.transitCities}}</text>
					</view>
					<view class="check-time row-between">
						<text>预计起止时间:</text>
						<text style="color: #1a1a1a">{{item.expectedStartTime}}—{{item.expectedArrivalTime}}</text>
					</view>
					<view class="quotation">
						<view class="quotation-left">
							<view class="quotation-carrier">
								<!-- logo 缺-->
								<!-- <view class="carrier-logo">
									<image style="height: 36rpx;width: 36rpx;" src="@/static/images/mine/aboutUs.png"
										mode="widthFix"></image>
								</view> -->
								<text>{{item.companyName}} </text>
								<view class="auth-iden" v-if="item.isApproved == 1">
									<!-- 切图缺 -->
									<uni-icons type="person" color="#1777FF" size="18"></uni-icons>
									企业认证
								</view>
								<view class="auth-iden-yu">
									{{forrmatterEnmu(Enmu.carType, item.vehicleType)}}
								</view>
							</view>
							<view class="quotation-release">
								{{item.createTime}}发布
							</view>
						</view>
						<button class="quotation-right" @click.stop="offterVehicle(1,item)" :disabled="item.status == '下架'">
							<text>下架</text>
						</button>
					</view>
				</view>
			</template>
			
			
			<!-- 买卖车 -->
			<!-- <view class="sellCar">
				<image style="height: 180rpx;width: 240rpx;" src="@/static/images/mine/car.png" mode="widthFix">
				</image>
				<view>
					<text>青岛解放 解放JK6(大柴)220马力(CA4DK1-22E61)柴油青岛解放 解放JK6(大柴)220马力(CA4DK1-22E61)柴油</text>
					<text>二手车 / 武汉牌照</text>
					<view>
						<text>23.98万</text>
						<text>下架该信息</text>
					</view>
				</view>
			</view> -->
		</scroll-view>

		<!-- <you-tabs :activeName="tabActive" :tabsList="tabsList" @tabClick="clickTabItem" :showMoreTab="true"></you-tabs> -->
		<!-- 	<you-scroll 
			:loadingHeight="loadingHeight" 
			:mainHeight="scrollHeight" 
			:isAllData="isAllData"
			:isRequestSuccess="isRequestSuccess" 
			@onRefresh="onRefresh" 
			@loadMore="loadMore">
			<template>
				
			</template>
		</you-scroll> -->
		<!-- <you-bottom-btn :btnConfig="bottomBtnConfig" @clickSubmit="clickSubmit"></you-bottom-btn> -->
	</view>
</template>

<script>
	import UserCenter from '../../api/userCenter.js'
	import {
		showConfirm,
		fomatterAdressName
	} from '@/utils/common'
	import {
		baseIconUrl,
		baseImgUrl
	} from '@/config'
	import Enmu from '@/utils/enmu.js'
	import {
		forrmatterEnmu,
		isTomorrow
	} from '@/utils/index.js'
	export default {
		name: 'Store',
		components: {},
		data() {
			return {
				Enmu,
				loadingHeight: '',
				scrollHeight: '',
				// 找车
				carDemands: [],
				// 找货
				goodDemands: [],
				isClickTap: true,
				tabsList: [{
						name: "在找车",
						value: '1'
					},
					{
						name: "在找货",
						value: '2'
					},
				],
				tabActive: '1'
			}
		},

		async onLoad() {
			this.scrollHeight = this.$store.getters.heightData.mainHeight - 48;
			this.loadingHeight = this.$store.getters.heightData.mainHeight - 68;
			
		},
		async onShow() {
			this.getReleaseList();
		},
		methods: {
			forrmatterEnmu,
			isTomorrow,
			fomatterAdressName,
			clickSkip() {
				uni.navigateTo({
					url: '/subPages/details/searchCar'
				})
			},
			checkType(item) {
				this.tabActive = item.value;
			},
			async getReleaseList() {
				let res = await UserCenter.getMyDemandList();
				if (res.code == 200) {
					this.carDemands = res.data.carDemands || [];
					this.goodDemands = res.data.goodDemands || [];
				}
				console.log(res)
			},
			async offterVehicle(demandType, item) {
				if (!this.isClickTap) return;
				showConfirm('请再次确认是否下架').then(res => {
					if (res.confirm) {
						let obj = {};
						if (demandType == 1) {
							obj.goodDemandId = item.id;
						} else if (demandType == 2) {
							obj.carDemandId = item.id;
						}
						this.isClickTap = false;
						UserCenter.myDemandOffset({
								demandType,
								...obj
							}).then(res => {
								this.getReleaseList();
							})
							.finally(() => {
								this.isClickTap = true;
							});
					}
				})
			},
			clickTabItem(e) {
				this.tabActive = e;
			},
			toDetail(item) {
				uni.navigateTo({
					url: "/subPages/transport/detail/findCar?id=" + item.id + "&type=1"
				})
			},
			toGoodsDetail(item){
				uni.navigateTo({
					url: "/subPages/transport/detail/findGoods?id=" + item.id + "&type=1"
				})
			},

		}
	}
</script>
<style lang="scss" scoped>
	.tab-list {
		display: flex;
		align-items: center;
		justify-content: center;
		.tab-item {
			color: #000000;
			font-size: 30rpx;
			line-height: 1;
			opacity: 0.8;
			margin-left: 40rpx;
			// padding: 20rpx 0;
		}
	
		.active-item {
			display: flex;
			flex-direction: column;
			font-size: 34rpx;
	
			&::after {
				content: "";
				display: inline-block;
				height: 8rpx;
				width: 68rpx;
				background: linear-gradient(90deg, #2f85ff1a 0%, #2F85FF 100%);
				border-radius: 6rpx;
			}
		}
	}
	.content-box {
		height: calc(100vh - 60rpx);
		padding: 30rpx;
		padding-top: 0;
		background: #ffffff;
		font-family: "PingFang SC";

		.vehicleSearch {
			padding: 30rpx 0;
			border-bottom: 2rpx solid #ddd;
			.base-info {
				display: flex;
				font-size: 24rpx;
				color: #333;
				justify-content: space-between;
				align-items: center;
				line-height: 1;

				.base-info-left {
					display: flex;
					line-height: 1;
				}

				.header-img {
					width: 36rpx;
					height: 36rpx;
					margin-right: 12rpx;
				}

				.release-item {
					color: #999;
				}
			}

			.to-place {
				font-size: 30rpx;
				color: #1A1A1A;

				image {
					width: 35rpx;
					height: 8rpx;
					margin: 0 12rpx;
					vertical-align: middle;
				}
			}

			.place-number {
				font-size: 44rpx;
				color: #1777FF;
				margin-top: 20rpx;
			}

			.car-info {
				color: #ff7512;
				font-size: 26rpx;
				margin-top: 20rpx;
				line-height: 1;
			}

			.check-time {
				color: #9F9F9F;
				font-size: 24rpx;
				margin-top: 18rpx;
				line-height: 1;

				.dimension {
					color: #1777ff;
					margin: 20rpx;
				}

				.dimension-fill {
					color: #1C1C1C;
					font-size: 26rpx;
				}
			}

			.quotation {
				display: flex;
				justify-content: space-between;
				font-size: 24rpx;
				margin-top: 10rpx;

				.quotation-price {
					color: #1777FF;
				}

				.quotation-Bidding {
					color: #4D4D4D;
				}

				.quotation-btn {
					width: 172rpx;
					height: 64rpx;
					border-radius: 8rpx;
					font-size: 28rpx;
					text-align: center;
					line-height: 64rpx;
				}

				.quotation-carrier {
					display: flex;
					font-size: 24rpx;
					color: #1A1A1A;
					margin-top: 10rpx;

					.carrier-logo {
						width: 36rpx;
						height: 36rpx;
						margin-right: 12rpx;
					}

					.auth-iden {
						font-size: 20rpx;
						padding: 6rpx 12rpx;
						background: #D1E5FF;
						color: #1777FF;
						border-radius: 4rpx;
						margin-left: 12rpx;
					}

					.auth-iden-yu {
						color: #ff7512;
						font-size: 20rpx;
						padding: 6rpx 10rpx;
						background: #FFE3D1;
						border-radius: 4rpx;
						margin-left: 12rpx;
					}
				}

				.quotation-release {
					font-size: 24rpx;
					color: #9F9F9F;
					margin-top: 10rpx;
				}

				.quotation-right {
					background: #1777FF;
					color: #fff;
					width: 172rpx;
					height: 64rpx;
					text-align: center;
					line-height: 64rpx;
					font-size: 28rpx;
					font-weight: 400;
					border-radius: 8rpx;
					align-self: flex-end;
					margin: 0;
				}

				.quoteNow {
					background: #1777FF;
					color: #fff;
					margin-left: 20rpx;
				}

				.iphone {
					color: #1777FF;
					border: 2rpx solid #1777FF;
				}
			}
		}
		
		.opcityDom {
			opacity: .5;
		}

		.sellCar {
			padding: 30rpx 0;
			display: flex;

			>view {
				width: calc(100% - 260rpx);
				margin-left: 20rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				>text {
					&:nth-of-type(1) {
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						overflow: hidden;
						width: 100%;
						font-family: "PingFang SC";
						font-size: 30rpx;
					}

					&:nth-of-type(2) {
						font-family: "PingFang SC";
						font-size: 24rpx;
					}
				}

				>view {
					display: flex;
					justify-content: space-between;

					text {
						color: #1777FF;
						font-family: "PingFang SC";
						font-size: 32rpx;

						&:nth-of-type(1) {}

						&:nth-of-type(2) {}
					}
				}
			}
		}
	}
</style>